package org.tabletopmachine;

import java.net.URL;

import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.GameState;
import org.tabletopmachine.match.Match;
import org.tabletopmachine.states.mainmenu.MainMenuState;
import org.tabletopmachine.states.preparation.TopBottomChoiceState;
import org.tabletopmachine.twl.TWLStateBasedGame;

public class Game extends TWLStateBasedGame {

	private static Game _gameInstance;
	private static Match _currentMatch;
	public GameState gameState;

	public Game(String gameTitle) {
		super(gameTitle);
		_gameInstance = this;
	}

	@Override
	public void initStatesList(GameContainer gc) throws SlickException {

		MainMenuState menustate = new MainMenuState();
		TopBottomChoiceState prepstate = new TopBottomChoiceState();

		this.addState(menustate);
		this.addState(prepstate);
		this.enterState(0);
	}

	public void shutdown() {
		AppGameContainer app = (AppGameContainer) this.getContainer();
		if (app != null) {
			app.destroy();
		}
		System.exit(0);
	}

	public static Game getGameInstance() {
		return _gameInstance;
	}

	@Override
	protected URL getThemeURL() {
		return Game.class.getResource("../../../res/gui/ttm2/ttm2.xml");
	}

	public static void initNewMatch() {
		_currentMatch = new Match();
		_currentMatch.initNewMatch();
	}

	public static Match getMatch() {
		return _currentMatch;
	}

}
